package com.lgl.scsheader.sameCityManage.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lgl.scsapi.base.dao.DaoSupport;
import com.lgl.scsapi.system.model.AppUser;
import com.lgl.scsapi.system.model.PageData;
import com.lgl.scsapi.util.utils.Constants;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 同城用户service
 */

@Service("sameCityUserService")
public class SameCityUserService {
	@Resource(name = "daoSupport")
	private DaoSupport dao;

	/**
	 * 获取同城用户信息
	 * @param pd 参数
	 * @return 用户集合
	 */
	public PageInfo listAppUser(PageData pd, int pageNo, int pageSize){
		if (pageSize < 1){
			pageSize = Constants.PAGE_SIZE;
		}
		if (pageNo < 1){
			pageNo = 1;
		}
		PageHelper.startPage(pageNo,pageSize);
		List<AppUser> userList = (List<AppUser>) dao.findForList("AppUserMapper.listAppUser", pd);
		return new PageInfo(userList);
	}

	/**
	 * 修改同城用户
	 * @param editUserPd 修改的参数
	 * @return 更新的行数，-1：表示因editUserPd为空而未执行更新操作
	 */
	public int editAppUser(PageData editUserPd){
		if (editUserPd == null || editUserPd.isEmpty()){
			return -1;
		}
		return dao.update("AppUserMapper.editAppUser", editUserPd);
	}
	/**
	 * 获取用户所有/今天/昨天总数
	 * @return 订单数据集合
	 */
	public List<PageData> listTodayYesterdayUser(){
		return (List<PageData>) dao.findForList("AppUserMapper.listTodayYesterdayUser", null);
	}
}